{% extends "../component/_latout.html" %}
{% block style %}
<link href="/public/admin/css/plugins/summernote/summernote.css" rel="stylesheet">
<link href="/public/admin/css/plugins/summernote/summernote-bs3.css" rel="stylesheet">
{% endblock %}
{% block content %}
<!--wrap-->
<div class="wrapper wrapper-content animated fadeInRight">
    <!--主体部分-->
    <div class="row">
        <!--左边部分-->
        <div class="col-sm-9">
          <div class="ibox float-e-margins">
              <div class="ibox-title">
                  <h5>文章-编辑文章</h5>
                  <div class="ibox-tools">
                    <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                    </a>
                  </div>
              </div>
              <div class="ibox-content">
                <form method="get" class="form-vertical">
                  <input type="hidden" id="articleId" value="{{article.id}}">
                  <div class="form-group m-b-lg">
                      <label class="control-label">文章标题</label>
                      <div>
                          <input  id="title" type="text" class="form-control" placeholder="在此输入标题" value="{{ article.title }}">
                      </div>
                  </div>
                  <div class="form-group  m-b-lg">
                      <label class="control-label">新闻分类</label>
                      <div>
                          <select class="form-control m-b" id="type">
                            <option value="" >请选择分类</option>
                              {% for articleType in articleTypes %}
                                <optgroup label="{{ articleType.name }}">
                                    {# <option value="{{ articleType.id }}" {% if article.type == articleType.id %}selected{% endif %}>{{ articleType.name }}</option> #}
                                    {% if articleType.children.length !== 0 %}
                                    {% for subarticleType in articleType.children %}
                                    <option value="{{ subarticleType.id }}" {% if article.type == subarticleType.id %}selected{% endif %}>{{ subarticleType.name }}</option>
                                        {% if subarticleType.children.length !== 0 %}
                                        {% for thirdarticleType in subarticleType.children %}
                                        <option value="{{ thirdarticleType.id }}" {% if article.type == thirdarticleType.id %}selected{% endif %}>├─{{ thirdarticleType.name }}</option>
                                        {% endfor %}
                                        {% endif %}
                                    {% endfor %}
                                    {% endif %}
                                </optgroup>
                              {% endfor %}
                        </select>
                      </div>
                  </div>
                  <!--作者-->
                  <div class="form-group  m-b-lg">
                      <label class="control-label">作者</label>
                      <div>
                          <input id="author" type="text" class="form-control" placeholder="在此输入作者" value="{{ article.author }}">
                      </div>
                  </div>
                  <!--/作者-->
                  <div class="form-group  m-b-lg">
                      <label class="control-label">图片</label>
                      <div>
                          <input id="img" type="text" class="form-control" placeholder="在此输入图片地址（可以去资源库复制图片链接）" value="{{ article.img }}">
                      </div>
                      <div class="m-t {% if article.img %}{% else %}hide{% endif %}" id="show-img">
                            <img src="{{ article.img }}"  width="60" height="60">
                      </div>
                  </div>
                  <!--摘要-->
                  <div class="form-group  m-b-lg">
                      <label class="control-label">摘要</label>
                      <div>
                          <input id="sub_title" type="text" class="form-control" placeholder="在此输入摘要" value="{{ article.sub_title }}">
                      </div>
                  </div>
                  <!--/摘要-->
                  <!--搜索关键词-->
                  <div class="form-group  m-b-lg">
                      <label class="control-label">搜索关键词</label>
                      <div>
                          <input id="keywords" type="text" class="form-control" placeholder="在此输入搜索关键词" value="{{ article.keywords }}">
                      </div>
                  </div>
                  <!--/搜索关键词-->
                  <!--来源-->
                  <div class="form-group  m-b-lg">
                      <label class="control-label">来源</label>
                      <div>
                          <input id="source" type="text" class="form-control" placeholder="在此输入来源" value="{{ article.source }}">
                      </div>
                  </div>
                  <!--/摘要-->
                  <!--添加媒体和附件(这个可能暂时不需要)-->
                  <div class="clear m-b">
                    <button type="button" class="btn btn-outline btn-primary add-attachment">添加附件</button>
                    <div class="attachment-list">
                        {% if article.file %}
                        <div class="file-item form-control no-border clearfix" fileid="{{article.file.id}}">
                            {% if article.file.type == 1 %}
                            <i class="fa fa-picture-o text-success" aria-hidden="true"></i>
                            {% elseif article.file.type == 2 %}
                            <i class="fa fa-file-pdf-o text-success" aria-hidden="true"></i>
                            {% elseif article.file.type == 3 %}
                            <i class="fa fa-video-camera text-success" aria-hidden="true"></i>
                            {% endif %}
                            <a href="{{article.file.url}}" target="_blank" class="text-success">{{article.file.name}}</a>
                            <span class="close" title="删除 {{article.file.name}}">
                                <i class="fa fa-times" aria-hidden="true"></i>
                            </span>
                        </div>
                        {% endif %}
                        {# <div class="form-control no-border clearfix">aaa <span class="close"><i class="fa fa-times" aria-hidden="true"></i></span></div> #}
                    </div>
                  </div>
                  <!--附件说明-->
                  <div class="form-group  m-b-lg">
                      <label class="control-label">附件说明</label>
                      <div>
                          <textarea id="attachments_notation" type="text" class="form-control" placeholder="在此输入附件说明">{{ article.attachments_notation }}</textarea>
                      </div>
                  </div>
                  <!--/附件说明-->
                  <!--相关文章-->
                  <div class="form-group  m-b-lg">
                        <label class="control-label">相关文章 [ 请去文章列表复制文章id用英文半角逗号 (,) 隔开 ]</label>
                        <div>
                            <input id="relative_article" type="text" class="form-control" placeholder="在此输入来源" value="{{ article.relative_article }}">
                        </div>
                  </div>
                  <!--/相关文章-->
                  <!--编辑器-->
                  <div class="summernote">
                      {{  article.content | safe }}
                  </div>
                </form>
              </div>
          </div>
        </div>

        <!--右边部分-->
        <div class="col-sm-3">
          {% if article %}
          <div class="ibox float-e-margins">
              <div class="ibox-title">
                    <h5>资源信息</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
              </div>
              <div class="ibox-content">
                    <div class="file-info-detail">
                        <div class="clearfix  m-b-sm">
                            <strong>浏览量:</strong> {{article.view_count}}
                        </div>
                        <div class="clearfix  m-b-sm">
                            <strong>最后操作用户:</strong> {{article.user.real_name}}
                        </div>
                        <div class="clearfix  m-b-sm">
                            <strong>发布状态:</strong> {% if article.publish == 0 %}未发布{%else%}已发布{% endif %}
                        </div>
                        <div class="clearfix  m-b-sm">
                            <strong>创建时间:</strong> {{article.create_time}}
                        </div>
                        <div class="clearfix  m-b-sm">
                            <strong>修改时间:</strong> {{article.modify_time}}
                        </div>
                        {% if article.publish == 1 %}
                        <div class="clearfix  m-b-sm">
                            <strong>发布时间:</strong> {{article.publish_time}}
                        </div>
                        {% endif %}
                    </div>
              </div>
          </div>
          {% endif %}
          <div class="ibox float-e-margins">
              <div class="ibox-title">
                  <h5>发布</h5>
                  <div class="ibox-tools">
                    <a class="collapse-link">
                      <i class="fa fa-chevron-up"></i>
                    </a>
                  </div>
              </div>
              <div class="ibox-content">
                  <div class="clearfix m-b-sm" id="publish_optBtn">
                    <div class="pull-left line-height-35">
                        <i class="fa {% if article.publish == 1 %}fa-eye{% else %}fa-eye-slash{% endif %}"></i>
                        <span class="nav-label">状态：{% if  article.publish == 1 %}已发布{% else %}未发布{% endif %}</span>
                    </div>
                    {% if article %}
                    <button type="button" articleId="{{article.id}}" publish="{{article.publish}}" class="btn btn-success pull-right m-b-none">{% if article.publish == 1 %}取消发布{% else %}发布{% endif %}</button>
                    {% endif %}
                  </div>
                  <div class="clearfix">
                    <button type="button" class="btn btn-primary pull-right m-b-none saveArticle" fileIds="{{article.file_ids}}" x-csrf-token = {{ctx.csrf}}>{% if article %}更新{% else %}保存{% endif %}</button>
                  </div>
              </div>
          </div>
          {% if article %}
          <div class="ibox m-b-none float-e-margins">
              <div class="ibox-title">
                  <h5>最近读者</h5>
                  <div class="ibox-tools">
                      <a class="J_menuItem" tabname="{{ article.title }} | 最近读者" href="/admin/operation/list?type=2&targetType=1&targetId={{ctx.query.articleId}}">
                          查看更多
                      </a>
                      <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                      </a>
                  </div>
              </div>
              <div class="ibox-content">
                  <div class="row">
                    {% for log in operations %}
                    <div class="col-sm-3 tx-c m-b no-padding" >
                      <div class="img-container m-b-xs">
                        <img class="img-circle" src="{{ log.user.avatar }}"  width="40" height="40">
                      </div>
                      {{ log.user.real_name }}
                    </div>
                    {% else %}
                    <!--没有数据时的显示-->
                    <div class="no-data-container">
                      <i class="fa fa-frown-o"></i>
                      <span>暂时还没有读者哦~</span>
                    </div>
                    <!--/没有数据时的显示-->
                    {% endfor %}
                  </div>
              </div>
          </div>
          
          {% endif %}
        </div>
    </div>
    <div class="row">
        <div class="col-sm-9">
            <div class="ibox float-e-margins">
                {# <div class="ibox-title">
                    <h5>发布</h5>
                    <div class="ibox-tools">
                        <a class="collapse-link">
                        <i class="fa fa-chevron-up"></i>
                        </a>
                    </div>
                </div> #}
                <div class="ibox-content">
                    <div class="clearfix tx-c">
                        <button type="button" class="btn btn-primary m-b-none saveArticle" fileIds="{{article.file_ids}}" x-csrf-token = {{ctx.csrf}}>{% if article %}更新{% else %}保存{% endif %}</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--/主体部分-->
</div>

{% endblock %} 
{% block script %}
<script src="/public/admin/js/plugins/summernote/summernote.js"></script>
<script src="/public/admin/js/plugins/summernote/summernote-zh-CN.js"></script>
<script src="/public/admin/js/common/article/edit.js"></script>
{% endblock %} 
